home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / as / dist / as.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-01  |  8.3 KB  |  289 lines

  1. /* as.h - global header file
  2.    Copyright (C) 1987 Free Software Foundation, Inc.
  3.  
  4. This file is part of GAS, the GNU Assembler.
  5.  
  6. GAS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GAS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GAS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #ifndef asH
  21. #define asH            /* Don't declare things twice. */
  22.  
  23. #ifdef USG
  24. #define index strchr
  25. #define bzero(s,n) memset((s),0,(n))
  26. #define bcopy(from,to,n) memcpy((to),(from),(n))
  27. #define setbuffer(a,b,c)
  28. #endif
  29.  
  30. /*
  31.  * CAPITALISED names are #defined.
  32.  * "lowercaseH" is #defined if "lowercase.h" has been #include-d.
  33.  * "lowercaseT" is a typedef of "lowercase" objects.
  34.  * "lowercaseP" is type "pointer to object of type 'lowercase'".
  35.  * "lowercaseS" is typedef struct ... lowercaseS.
  36.  *
  37.  * #define SUSPECT when debugging.
  38.  * #define DUMP to include data-structure dumpers.
  39.  * #define COMMON as "extern" for all modules except one, where you #define
  40.  *    COMMON as "".
  41.  * If TEST is #defined, then we are testing a module: #define COMMON as "".
  42.  */
  43.  
  44.  
  45.  
  46. /* These #defines are for parameters of entire assembler. */
  47.  
  48. /* #define SUSPECT JF remove for speed testing */
  49. /* #define DUMP */
  50. #define NDEBUG        /* JF disable asserts */
  51. /* These #includes are for type definitions etc. */
  52.  
  53. /* #include "style.h" */
  54. #include <stdio.h>
  55. #include <assert.h>
  56. #define obstack_chunk_alloc    xmalloc
  57. #define obstack_chunk_free    xfree
  58.  
  59. /* These defines are potentially useful */
  60. #define FALSE    (0)
  61. #define TRUE    (!FALSE)
  62. #define ASSERT    assert
  63. #define BAD_CASE(value)                            \
  64. {                                    \
  65.   as_fatal ("Case value %d unexpected at line %d of file \"%s\"\n",    \
  66.        value, __LINE__, __FILE__);                    \
  67. }
  68.  
  69.  
  70.  
  71.  
  72. /* These are assembler-wide concepts */
  73.  
  74.  
  75. #ifndef COMMON
  76. #ifdef TEST
  77. #define COMMON            /* declare our COMMONs storage here. */
  78. #else
  79. #define COMMON extern        /* our commons live elswhere */
  80. #endif
  81. #endif
  82.                 /* COMMON now defined */
  83.  
  84. #ifdef SUSPECT
  85. #define register        /* no registers: helps debugging */
  86. #define know(p) ASSERT(p)    /* know() is less ugly than #ifdef SUSPECT/ */
  87.                 /* assert()/#endif. */
  88. #else
  89. #define know(p)            /* know() checks are no-op.ed */
  90. #endif                /* #ifdef SUSPECT */
  91.  
  92.  
  93. char    *xmalloc();        /* keep C compilers happy */
  94. char    *xrealloc();        /* " */
  95. void    free();            /* " */
  96. #define xfree free
  97.  
  98. /* input_scrub.c */
  99.  
  100. /*
  101.  * Supplies sanitised buffers to read.c.
  102.  * Also understands printing line-number part of error messages.
  103.  */
  104.  
  105.                 /* Line number things. */
  106. int    seen_at_least_1_file();
  107. void    bump_line_counters();
  108. void    new_logical_line();
  109. void    as_where();
  110. void    as_perror();
  111. void    as_howmuch();
  112.                 /* Sanitising things. */
  113. void    input_scrub_begin();
  114. void    input_scrub_end();
  115. char    *input_scrub_new_file();
  116. char    *input_scrub_next_buffer();
  117.  
  118. /* subsegs.c     Sub-segments. Also, segment(=expression type)s.*/
  119.  
  120. /*
  121.  * This table describes the use of segments as EXPRESSION types.
  122.  *
  123.  *    X_seg    X_add_symbol  X_subtract_symbol    X_add_number
  124.  * SEG_NONE                        no (legal) expression
  125.  * SEG_PASS1                        no (defined) "
  126.  * SEG_BIG                    *    > 32 bits const.
  127.  * SEG_ABSOLUTE                         0
  128.  * SEG_DATA        *                 0
  129.  * SEG_TEXT        *            0
  130.  * SEG_BSS        *            0
  131.  * SEG_UNKNOWN        *            0
  132.  * SEG_DIFFERENCE    0        *    0
  133.  *
  134.  * The blank fields MUST be 0, and are nugatory.
  135.  * The '0' fields MAY be 0. The '*' fields MAY NOT be 0.
  136.  *
  137.  * SEG_BIG: X_add_number is < 0 if the result is in
  138.  *    generic_floating_point_number.  The value is -'c' where c is the
  139.  *    character that introduced the constant.  e.g. "0f6.9" will have  -'f'
  140.  *    as a X_add_number value.
  141.  *    X_add_number > 0 is a count of how many littlenums it took to
  142.  *    represent a bignum.
  143.  * SEG_DIFFERENCE:
  144.  * If segments of both symbols are known, they are the same segment.
  145.  * X_add_symbol != X_sub_symbol (then we just cancel them, => SEG_ABSOLUTE).
  146.  */
  147.  
  148. typedef enum
  149. {
  150.     SEG_ABSOLUTE,
  151.     SEG_TEXT,
  152.     SEG_DATA,
  153.     SEG_BSS,
  154.     SEG_UNKNOWN,
  155.     SEG_NONE,        /* Mythical Segment: NO expression seen. */
  156.     SEG_PASS1,        /* Mythical Segment: Need another pass. */
  157.     SEG_GOOF,        /* Only happens if AS has a logic error. */
  158.                 /* Invented so we don't crash printing */
  159.                 /* error message involving weird segment. */
  160.     SEG_BIG,            /* Bigger than 32 bits constant. */
  161.     SEG_DIFFERENCE        /* Mythical Segment: absolute difference. */
  162. }        segT;
  163. #define SEG_MAXIMUM_ORDINAL (SEG_DIFFERENCE)
  164.  
  165. typedef unsigned char    subsegT;
  166.  
  167. COMMON subsegT            now_subseg;
  168.                 /* What subseg we are accreting now? */
  169.  
  170.  
  171. COMMON segT            now_seg;
  172.                 /* Segment our instructions emit to. */
  173.                 /* Only OK values are SEG_TEXT or SEG_DATA. */
  174.  
  175.  
  176. extern char    *seg_name[];
  177. extern int    seg_N_TYPE[];
  178. extern segT    N_TYPE_seg[];
  179. void    subsegs_begin();
  180. void    subseg_change();
  181. void    subseg_new();
  182.  
  183. /* relax() */
  184.  
  185. typedef enum
  186. {
  187.     rs_fill,        /* Variable chars to be repeated fr_offset */
  188.                 /* times. Fr_symbol unused. */
  189.                 /* Used with fr_offset == 0 for a constant */
  190.                 /* length frag. */
  191.  
  192.     rs_align,        /* Align: Fr_offset: power of 2. */
  193.                 /* 1 variable char: fill character. */
  194.     rs_org,            /* Org: Fr_offset, fr_symbol: address. */
  195.                 /* 1 variable char: fill character. */
  196.  
  197.     rs_machine_dependent,
  198. #ifndef WORKING_DOT_WORD
  199.     rs_broken_word,        /* JF: gunpoint */
  200. #endif
  201. }
  202. relax_stateT;
  203.  
  204. /* typedef unsigned char relax_substateT; */
  205. /* JF this is more likely to leave the end of a struct frag on an align
  206.    boundry.  Be very careful with this.  */
  207. typedef unsigned long int relax_substateT;
  208.  
  209. typedef unsigned long int relax_addressT;/* Enough bits for address. */
  210.                 /* Still an integer type. */
  211.  
  212.  
  213. /* frags.c */
  214.  
  215. /*
  216.  * A code fragment (frag) is some known number of chars, followed by some
  217.  * unknown number of chars. Typically the unknown number of chars is an
  218.  * instruction address whose size is yet unknown. We always know the greatest
  219.  * possible size the unknown number of chars may become, and reserve that
  220.  * much room at the end of the frag.
  221.  * Once created, frags do not change address during assembly.
  222.  * We chain the frags in (a) forward-linked list(s). The object-file address
  223.  * of the 1st char of a frag is generally not known until after relax().
  224.  * Many things at assembly time describe an address by {object-file-address
  225.  * of a particular frag}+offset.
  226.  
  227.  BUG: it may be smarter to have a single pointer off to various different
  228. notes for different frag kinds. See how code pans out.
  229.  
  230.  
  231.  */
  232. struct frag            /* a code fragment */
  233. {
  234.     long unsigned int fr_address; /* Object file address. */
  235.     struct frag *fr_next;    /* Chain forward; ascending address order. */
  236.                 /* Rooted in frch_root. */
  237.  
  238.     long int fr_fix;    /* (Fixed) number of chars we know we have. */
  239.                 /* May be 0. */
  240.     long int fr_var;    /* (Variable) number of chars after above. */
  241.                 /* May be 0. */
  242.     struct symbol *fr_symbol; /* For variable-length tail. */
  243.     long int fr_offset;    /* For variable-length tail. */
  244.     char    *fr_opcode;    /*->opcode low addr byte,for relax()ation*/
  245.     relax_stateT fr_type;   /* What state is my tail in? */
  246.     relax_substateT    fr_subtype;
  247.         /* These are needed only on the NS32K machines */
  248.     char    fr_pcrel_adjust;
  249.     char    fr_bsr;
  250.     char    fr_literal [1];    /* Chars begin here. */
  251.                 /* One day we will compile fr_literal[0]. */
  252. };
  253. #define SIZEOF_STRUCT_FRAG \
  254.  ((int)zero_address_frag.fr_literal-(int)&zero_address_frag)
  255.                 /* We want to say fr_literal[0] above. */
  256.  
  257. typedef struct frag fragS;
  258.  
  259. COMMON fragS *    frag_now;    /* -> current frag we are building. */
  260.                 /* This frag is incomplete. */
  261.                 /* It is, however, included in frchain_now. */
  262.                 /* Frag_now->fr_fix is bogus. Use: */
  263. /* Virtual frag_now->fr_fix==obstack_next_free(&frags)-frag_now->fr_literal.*/
  264.  
  265. COMMON fragS zero_address_frag;    /* For foreign-segment symbol fixups. */
  266. COMMON fragS  bss_address_frag;    /* For local common (N_BSS segment) fixups. */
  267.  
  268. void        frag_new();
  269. char *        frag_more();
  270. char *        frag_var();
  271. void        frag_wane();
  272. void        frag_align();
  273.  
  274.  
  275. /* main program "as.c" (command arguments etc) */
  276.  
  277. COMMON char
  278. flagseen[128];            /* ['x'] TRUE if "-x" seen. */
  279.  
  280. COMMON char *
  281. out_file_name;            /* name of emitted object file */
  282.  
  283. COMMON int    need_pass_2;    /* TRUE if we need a second pass. */
  284.  
  285.  
  286. #endif                /* #ifdef asH */
  287.  
  288. /* end: as.h */
  289.